<template>
  <view class="page-wrap">
    <view class="list-box" v-if="tabs.length === 0">
      <list-bar @change="changeSerchVal" :background-class='listBarBg' :listType="listType" :filterCols="filterCols"
        :srvApp="appName" :gridButtonDisp="gridButtonDisp" :rowButtonDisp="rowButtonDisp" :srvCols="srvCols"
        :placholder="placeholder" :listButton="listButton" @toOrder="toOrder" @toFilter="toFilter"
        @handelCustomButton="handlerCustomizeButton" @clickAddButton="clickAddButton" @search="toSearch"
        :readonly="true" v-if="showListBar">
      </list-bar>
      <filter-tags :tabs="tags" ref="filterTabs" :mode="'fold'" :cols="colV2.srv_cols" :srv="serviceName"
        @on-input-value="onFilterChange" @on-change="getListWithFilter"
        v-if="showFilterBar&&colV2&&colV2.srv_cols&&tags">
      </filter-tags>
      <view class="title" :style="titleStyle" v-if="pageItem&&pageItem.show_label!=='否'&&showEmptyData">
        <text>{{ pageItem.component_label || '' }}</text>
        <view @click="toAll" v-if="isShowToAll">
          <text>更多</text>
          <text class="cuIcon-right"></text>
        </view>
      </view>
      <view class="tabs-view" v-if="tabsCfg&&tabsCfg.tabs&&tabsCfg.col">
        <u-tabs :list="enumTabs" :is-scroll="true" :current="curTab" :active-color="tabsCfg.activeColor"
          @change="changeTab"></u-tabs>
      </view>
      <view class="list-content" v-if="showEmptyData">
        <view class="list-view">
          <list-next class="list-next" :nowrap="nowrap" :itemWidth="itemWidth" :cartData="cartData"
            :listConfig="listConfig" :list="list" :listType="listType" :colV2="colV2" :appName="appName"
            @click-foot-btn="clickFootBtn" />
        </view>
      </view>

      <uni-load-more :status="loadStatus" v-if="loadOnReachBottom"></uni-load-more>
    </view>
    <view class="tabs-list list-box" v-else-if="tabs.length > 0">
      <u-tabs :list="tabs" :is-scroll="true" :current="curTab" style="margin: 0 10px 5px;" @change="changeTab">
      </u-tabs>
      <view class="list-content" :style="{
					backgroundColor: list_config.bg
				}" v-for="(item, index) in tabs" :key="index">
        <view class="list-view" v-if="index === curTab">
          <list-next class="list-next" :listConfig="listConfig" :list="list" :listType="listType" :colV2="colV2"
            :appName="appName" @click-foot-btn="clickFootBtn" />
        </view>
      </view>
    </view>
  </view>
</template>

<script>
  import listNext from '@/components/list-next/list-next.vue';
  // import listNext from '../../components/list-next/list-next.vue';
  export default {
    components: {
      listNext,
    },
    props: {
      pageItem: {
        type: Object
      }
    },
    computed: {
      enumTabs() {
        return this.tabsCfg?.tabs || []
      },
      loadOnReachBottom() {
        return this.pageItem?.load_on_reach_bottom || this.config?.loadOnReachBottom
      },
      tags() {
        if (Array.isArray(this.colV2?.tabs)) {
          let tabs = this.colV2?.tabs
          let self = this
          let tab = {}
          let tabsData = []
          tabs.forEach((t) => {
            tab = {
              service: null,
              table_name: null,
              orders: null,
              conditions: null,
              seq: null,
              parent: null,
              label: null,
              list_tab_no: null,
              more_config: null,
              inputType: null
            }
            let mc = JSON.parse(t.more_config)
            tab.more_config = mc
            tab.service = t.service
            tab.table_name = t.table_name
            tab.conditions = t.conditions
            tab.orders = t.orders
            tab.default = mc.default
            tab.seq = t.seq
            tab.label = t.label
            tab.list_tab_no = t.list_tab_no
            tab._data = t
            tab._type = mc.type || null
            tab._colName = mc.colName || null
            tab.inputType = mc.inputType || null
            tab.showAllTag = mc.showAllTag || false
            tab.default = mc.default || ''
            tab.placeholder = mc.placeholder || '请输入...'

            if (tab._colName) {
              tab._colName = tab._colName.split(',')
              let cols = tab._colName
              let srvCols = self.colV2.srv_cols
              tab['_colSrvData'] = []
              for (let c = 0; c < cols.length; c++) {
                for (let cs = 0; cs < srvCols.length; cs++) {
                  if (cols[c] === srvCols[cs].columns) {
                    tab._colSrvData.push(srvCols[cs])
                  }
                }
              }
            }
            tabsData.push(tab)
          })
          return tabsData
        }
        // return this.colV2?.tabs
      },
      showListBar() {
        return this.pageItem && this.pageItem.show_list_bar == '是' && this.srvCols && this.srvCols.length > 0 && this
          .list_config.list_bar !== false
      },
      showFilterBar() {
        return this.pageItem && this.pageItem.show_filter_bar == '是'
      },
      listBarBg() {
        let color = 'white'
        if (this.pageItem?.list_bar_bg) {
          switch (this.pageItem.list_bar_bg) {
            case '透明':
              color = 'transparent'
              break;
            case '透明':
              color = 'white'
              break;
          }
        }
        return `bg-${color}`
      },
      nowrap() {
        return this.pageItem?.list_is_auto_wrap === '否' && this.itemWidth ? true : false
      },
      itemWidth() {
        return this.pageItem?.list_item_width
      },
      tabs() {
        return Array.isArray(this.config?.tabs) && this.config.tabs.length > 0 ? this.config.tabs : [];
      },
      showEmptyData() {
        if (this.config?.showEmptyData == false && this.list.length === 0 && this.loadStatus === 'noMore') {
          return false;
        } else {
          return true;
        }
      },
      isShowToAll() {
        if (this.config?.showSeeAll == false) {
          return false;
        }
        let num = this.rownumber;
        if (this.total > num) {
          return true;
        }
        return false;
      },
      serviceName() {
        if (this.tabs?.length > 0) {
          return this.tabs[this.curTab].service || this.config?.serviceName;
        }
        return this.config?.serviceName;
      },
      appName() {
        if (this.tabs?.length > 0) {
          return this.tabs[this.curTab].app || this.config?.appName || uni.getStorageSync('activeApp');
        }
        return this.config?.appName || uni.getStorageSync('activeApp');
      },
      publicButton() {
        if (Array.isArray(this.colV2?.gridButton) && this.colV2?.gridButton.length > 0) {
          return this.colV2.gridButton;
        }
        return [];
      },
      moreConfig() {
        return this.colV2?.moreConfig || {};
      },
      config() {
        if (this.pageItem && this.pageItem.list_config) {
          let config = this.pageItem.list_config;
          if (typeof config === 'string') {
            try {
              config = JSON.parse(config);
            } catch (e) {
              //TODO handle the exception
              console.warn(e);
            }
          }
          return config;
        }
      },
      titleStyle() {
        if (typeof this.pageItem?.more_config === 'object') {
          return this.pageItem?.more_config?.titleStyle || '';
        }
      },
      listConfig() {
        if (this.tabs?.length > 0) {
          return this.tabs[this.curTab]['list_config'] || this.config?.list_config || {}
        }
        return this.config?.list_config || {};
      },
      list_config() {
        let config = this.colV2?.moreConfig?.list_config;
        let obj = {
          item_style: this.listConfig?.item_style || config?.item_style || '',
          bg: this.listConfig?.bg || config?.bg || '',
          lp_style: this.listConfig?.lp_style || config?.lp_style || '复合',
          grid_span: this.listConfig?.grid_span || config?.grid_span || '2',
          detailPage: this.listConfig?.detailPage || config?.detailPage,
          margin: this.listConfig?.margin || config?.margin,
          padding: this.listConfig?.padding || config?.padding,
          borderRadius: this.listConfig?.borderRadius || config?.borderRadius,
          list_bar: this.listConfig?.list_bar ?? config?.list_bar,
          btn_cfg: {
            margin: this.listConfig?.btn_cfg?.margin ?? config?.btn_cfg
              ?.margin,
            show_custom_btn: this.listConfig?.btn_cfg?.show_custom_btn ?? config?.btn_cfg
              ?.show_custom_btn ?? null,
            show_public_btn: this.listConfig?.btn_cfg?.show_public_btn ?? config?.btn_cfg
              ?.show_public_btn ?? null,
            show: config?.btn_cfg?.show || true,
            bg_style: this.listConfig?.btn_cfg?.bg_style || config?.btn_cfg?.bg_style || 'line',
            bg: this.listConfig?.btn_cfg?.bg || config?.btn_cfg?.bg,
            color: this.listConfig?.btn_cfg?.color || config?.btn_cfg?.color,
            font_size: this.listConfig?.btn_cfg?.font_size || config?.btn_cfg?.font_size,
            radius: this.listConfig?.btn_cfg?.radius || config?.btn_cfg?.radius || '10px',
            size: this.listConfig?.btn_cfg?.size || config?.btn_cfg?.size || 'sm',
            padding: this.listConfig?.btn_cfg?.padding || config?.btn_cfg?.padding || null
          },
          img: {
            col: this.listConfig?.img?.col || config?.img?.col,
            cfg: {
              width: this.listConfig?.img?.width || config?.img?.cfg?.width || '100%',
              height: this.listConfig?.img?.height || config?.img?.cfg?.height || '150rpx',
              radius: config?.img?.cfg?.radius || '10px 10px 0 0',
              position: config?.img?.cfg?.position || 'top',
              mode: this.listConfig?.img?.mode || config?.img?.cfg?.mode || '',
              padding: this.listConfig?.img?.padding || config?.img?.cfg?.padding || '',
              margin: this.listConfig?.img?.margin || config?.img?.cfg?.margin || ''
            }
          },
          cols: this.listConfig?.cols || config?.cols
        };
        if (typeof obj.item_style === 'object') {
          obj.item_style = JSON.stringify(obj.item_style);
        }
        return obj;
        // return this.colV2?.moreConfig?.list_config || {}
      },
      listButton() {
        let buttons = this.publicButton;
        let res = buttons
          .filter(item => {
            if (['select', 'add', 'apply', 'customize'].includes(item.button_type)) {
              if (item.button_type === 'select') {
                return this.colV2?._fieldInfo;
              }
              if (item.button_type === 'add') {
                return true;
              }
            }
          })
          .map(item => {
            if (item.button_type === 'select') {
              item.icon = 'cuIcon-filter';
              item.button_name = '筛选';
              item.clickEvent = this.showFilterModal;
            } else if (['add', 'apply'].includes(item.button_type)) {
              item.icon = 'cuIcon-add';
              item.clickEvent = this.clickAddButton;
            }
            return item;
          });
        if (Array.isArray(this.orderCols) && this.orderCols.length > 0) {
          res.push({
            button_type: 'order',
            icon: 'cuIcon-order',
            label: '排序',
            button_name: '排序',
            clickEvent: this.showOrder
          });
        }
        return res;
      },
      srvCols() {
        return this.colV2?._fieldInfo || [];
      },
      finalSearchColumn() {
        if (Array.isArray(this.srvCols) && this.srvCols.length > 0) {
          let arr = []
          if (Array.isArray(this.listConfig?.cols)) {
            let cols = this.listConfig?.cols.map(item => item.col)
            arr = this.srvCols.filter(item => cols.includes(item.column)).map(item => item.column)
          }
          return arr
        }
      },
      filterCols() {
        let cols = this.moreConfig?.appTempColMap;
        let arr = [];
        if (Array.isArray(this.srvCols) && this.srvCols.length > 0) {
          arr = this.srvCols.filter(item => !['Image', 'String', 'MultilineText',
            'Integer', 'Email', 'TelNo'
          ].includes(item
            .col_type) && (item.in_cond !== 0 || item.in_cond_def !== 0));
        }
        return arr;
      },
      orderList() {
        let cols = this.orderCols.filter(item => item.selected);
        if (cols.length === 0) {
          return this.order;
        }
        let arr = cols.map(col => {
          return {
            colName: col.columns,
            orderType: col.orderType || 'asc'
          };
        });
        return arr;
      },
      rownumber() {
        // return 10
        let rownumber = this.config?.page?.rownumber ?? 10;
        if (this.tabs?.length > 0 && this.tabs[this.curTab].page && this.tabs[this.curTab].page.rownumber) {
          rownumber = this.tabs[this.curTab].page.rownumber
        }
        return rownumber;
      }
    },
    data() {
      return {
        tabsData: [],
        curTab: 0, //当前选中tab的索引
        tabsCfg: null,
        curTabVal: null, //当前选中tab的值
        hideChildList: false,
        showMockCount: false,
        list: [],
        pageNo: 1,
        total: null,
        loadStatus: 'more',
        condition: null,
        colV2: null,
        orderCols: [],
        proc_data_type: '', //流程状态
        searchVal: '',
        listType: 'list', //list,proc,cart
        pageType: '', //list,proc,cart
        detailType: '', //  normal,custom
        tabList: [
          [],
          [],
          []
        ],
        order: [],
        cartData: [],
        wxMchId: '',
        customDetailUrl: '',
        initCond: [],
        relationCondition: [],
        gridButtonDisp: {
          refresh: false
        },
        rowButtonDisp: {},
        placeholder: "",
        loading: false,
        scrollListOption: {
          size: 5,
          auto: true
        }
      };
    },
    methods: {
      loadMore() {
        if (this.loadOnReachBottom && this.loadStatus === 'more') {
          // 允许触底加载
          if (this.rownumber * this.pageNo >= this.total) {
            this.loading = 'noMore'
            return
          } else {
            this.pageNo++;
            this.getList().then(_ => {
              this.loading = false
              // this.$refs.scrollList.loadSuccess({
              //   list: this.list,
              //   total: this.total
              // });
            })
          }
        }
      },
      changeTab(e) {
        this.curTab = e;
        // this.serviceName  = this.tabs[e].service||this.serviceName
        // this.appName  = this.tabs[e].app||this.appName
        console.log(e,this.tabsCfg?.type);
        if (this.tabsCfg?.type === 'fk_col'||this.tabsCfg?.type === 'enum_col') {
          let cond = null
          let tab = this.tabsCfg.tabs[e]
          if (tab.value) {
            if (tab.value !== '_all') {
              // cond = []
              cond = [{
                colName: this.tabsCfg?.col || this.tabsCfg?.column,
                ruleType: 'eq',
                value: tab.value
              }]
            } else {
              cond = []
              if (Array.isArray(this.enumTabs) && this.enumTabs.length > 1) {
                let val = this.enumTabs.filter(item => item.value !== '_all').map(item => item.value).toString()
                cond = [{
                  colName: this.tabsCfg?.col|| this.tabsCfg?.column,
                  ruleType: 'in',
                  value: val
                }]
              }
            }
            this.curTabVal = tab.value
            this.pageNo = 1;
            this.getList(cond)
          }
        } else {
          this.condition = this.tabs[e]?.condition || [];
          // this.getListV2().then(_ => {
          //   this.refresh();
          // });
        }

      },
      toAll() {
        let url = `/publicPages/list2/list2?serviceName=${this.serviceName}&destApp=${this.appName}`

        if (Array.isArray(this.config?.condition) && this.config?.condition.length > 0) {
          let conds = this.config?.condition

          let data = {
            userInfo: this.$store?.state?.user?.userInfo,
            storeInfo: this.$store?.state?.app?.storeInfo,
            bindUserInfo: this.$store?.state?.user?.storeUserInfo
          };
          conds = conds.map(cond => {
            let obj = {};
            obj.colName = cond.colName;
            obj.ruleType = cond.ruleType;
            obj.value = this.renderStr(cond.value, data);
            return obj
          });


          url += `&cond=${JSON.stringify(conds)}`
        }

        if (Array.isArray(this.config?.relation_condition?.data) && this.config.relation_condition?.data.length >
          0 &&
          this
          .tabs.length < 1) {
          let data = {
            userInfo: this.$store?.state?.user?.userInfo,
            storeInfo: this.$store?.state?.app?.storeInfo,
            bindUserInfo: this.$store?.state?.user?.storeUserInfo
          };
          try {
            let relation_condition = JSON.parse(this.renderStr(JSON.stringify(this.config
              ?.relation_condition), data));
            url += `&rCond=${JSON.stringify(relation_condition)}`
          } catch (err) {
            console.log(err);
          }
        }

        if (Array.isArray(this.config?.group) && this.config?.group.length > 0) {
          url += `&group=${JSON.stringify(this.config?.group)}`
        }

        uni.navigateTo({
          url: url
        });
      },
      getListWithFilter(e) {
        let self = this;
        let tabsConds = this.$refs.filterTabs.buildConditions();
        this.relationCondition = tabsConds;
        setTimeout(() => {
          this.pageNo = 1;
          this.getList(null, this.initCond);
        }, 100);
      },
      onFilterChange(e) {
        if (e) {
          let tabsConds = this.$refs.filterTabs.buildConditions();
          this.relationCondition = tabsConds;
        }
      },
      clearCart() {
        this.cartData = [];
      },
      changeAmount(data) {
        if (data && data.row && typeof data.index === 'number') {
          this.$set(this.cartData, data.index, data.row);
          if (data.row.goods_count === 0) {
            this.cartData.splice(data.index, 1);
          }
        }
      },
      toOrder(e) {
        this.order = e
        setTimeout(_ => {
          this.getList()
        }, 100)
      },
      toSearch(e) {
        let keywords = e || this.searchVal;
        this.searchVal = keywords
        this.pageNo = 1
        this.getList()
      },
      changeSerchVal(e) {
        this.searchVal = e
      },
      toFilter(e) {
        this.searchVal = ''
        this.showFilter = false;
        if (Array.isArray(e)) {
          let cond = e
          this.getList(cond)
        }
      },
      handlerCustomizeButton(e) {
        // 自定义按钮
        if (e.servcie_type === 'add') {
          let params = {
            type: 'add',
            serviceName: e.service_name,
            eventOrigin: e
          };
          uni.navigateTo({
            url: '/pages/public/formPage/formPage?params=' + JSON.stringify(params)
          });
        } else if (e.servcie_type === 'select') {
          let params = {
            type: 'select',
            serviceName: e.service_name,
            defaultVal: data.row,
            eventOrigin: e
          };
          if (e.operate_params && Array.isArray(e.operate_params.condition)) {
            let viewTemp = {};
            if (e.service_name === 'srvhealth_store_vaccination_appoint_record_select') {
              viewTemp = {
                title: 'customer_name',
                img: 'person_image'
              };
            }
            uni.navigateTo({
              url: '/publicPages/list/list?pageType=list&serviceName=' +
                e.service_name +
                '&cond=' +
                JSON.stringify(e.operate_params.condition) +
                '&viewTemp=' +
                JSON.stringify(viewTemp)
            });
          }
        } else if (e.servcie_type === 'update') {
          let fieldsCond = [];
          if (Array.isArray(this.condition)) {
            fieldsCond = this.condition.map(item => {
              return {
                column: item.colName,
                value: item.value,
                display: false
              };
            });
          }
          let condition = button?.operate_params?.condition;
          let defaultVal = button?.operate_params?.data;
          if (Array.isArray(defaultVal) && defaultVal.length > 0) {
            let obj = defaultVal[0];
            if (this.iObject(obj)) {
              Object.keys(obj).forEach(key => {
                fieldsCond.push({
                  column: key,
                  value: obj[key]
                });
              });
            }
          }
          if (Array.isArray(condition) && condition.length > 0) {
            condition.forEach(cond => {
              fieldsCond.push({
                column: cond.colName,
                value: cond.value
              });
            });
          }

          let url =
            `/publicPages/formPage/formPage?service=${e.service}&serviceName=${e.service_name}&type=${e.servcie_type}&fieldsCond=` +
            encodeURIComponent(JSON.stringify(fieldsCond));
          if (this.appName) {
            url += `&appName=${this.appName}`;
          }

          uni.navigateTo({
            url: url
          });
        }
      },
      clickAddButton(e) {
        if (e.button_type === 'add') {
          let fieldsCond = [];
          if (Array.isArray(this.condition)) {
            fieldsCond = this.condition.map(item => {
              return {
                column: item.colName,
                value: item.value,
                display: false
              };
            });
          }
          let url =
            `/publicPages/formPage/formPage?type=add&serviceName=${e.service_name.replace('_select', '_add')}&fieldsCond=${JSON.stringify(fieldsCond)}`;

          url =
            `/publicPages/formPage/formPage?type=add&serviceName=${e.service_name.replace('_select', '_add')}&fieldsCond=${JSON.stringify(fieldsCond)}`;

          if (this.appName) {
            url += `&appName=${this.appName}`;
          }
          if (this.main_data) {
            url += `&main_data=${JSON.stringify(this.main_data)}`;
          }
          uni.navigateTo({
            url: url
          });
        }
      },
      async refresh() {
        this.loadStatus = 'more';
        this.pageNo = 1;
        await this.getList(null, this.initCond);
        // this.$refs.scrollList.refreshSuccess({
        //   list: this.list,
        //   total: this.total
        // });
        return
      },
      async getFkTabs(srvInfo = {}) {
        const {
          serviceName,
          srv_app
        } = srvInfo
        if (serviceName && srv_app) {
          const url = `/${srv_app}/select/${serviceName}`
          const req = {
            "serviceName": serviceName,
            "colNames": ["*"],
            "condition": [],
            "page": {
              "rownumber": 20,
              "pageNo": 1
            }
          }
          if (Array.isArray(srvInfo?.conditions) && srvInfo?.conditions.length > 0) {
            req.condition = srvInfo?.conditions.map(item => {
              let data = {
                ...this.globalVariable
              }
              item.value = this.renderStr(item.value, data)
              return item
            })
          }
          const res = await this.$http.post(url, req);
          if (res?.data?.state === 'SUCCESS') {
            return res.data.data
          }
        }
      },
      async getListV2() {
        let app = this.appName || uni.getStorageSync('activeApp');
        let self = this;
        let colVs = await this.getServiceV2(this.serviceName, 'list', this.listType === 'proc' ? 'proclist' :
          'list', app);
        colVs?.srv_cols ? colVs.srv_cols = colVs.srv_cols.filter(item => item.in_list === 1 || item
            .in_list === 2) :
          ''
        console.log('colVs', colVs);
        if (colVs.more_config) {
          try {
            colVs.moreConfig = JSON.parse(colVs.more_config);
            if (colVs.moreConfig?.detailType) {
              if (!this.detailType) {
                this.detailType = colVs.moreConfig?.detailType;
              }
            }
            if (colVs.moreConfig?.customDetailUrl) {
              if (!this.customDetailUrl) {
                this.customDetailUrl = colVs.moreConfig?.customDetailUrl;
              }
            }
            // if (colVs.moreConfig?.formButtonDisp && !this.formButtonDisp) {
            // 	this.formButtonDisp = colVs.moreConfig?.formButtonDisp
            // }
            if (colVs.moreConfig?.rowButtonDisp && !this.rowButtonDisp) {
              this.rowButtonDisp = colVs.moreConfig?.rowButtonDisp
            }
            if (colVs.moreConfig?.gridButtonDisp && !this.gridButtonDisp) {
              this.gridButtonDisp = colVs.moreConfig?.gridButtonDisp
            }
          } catch (e) {
            //TODO handle the exception
            console.info(e);
          }
        }
        if (colVs?.moreConfig?.tabs_cfg) {
          let tabsCfg = colVs?.moreConfig?.tabs_cfg;
          if (tabsCfg?.column && !tabsCfg.col) {
            tabsCfg.col = tabsCfg?.column
          }
          tabsCfg.activeColor = tabsCfg?.active_color
          tabsCfg.tabs = []
          // if (tabsCfg?.show_total_tab !== false) {
          //   tabsCfg.tabs = [{
          //     value: '_all',
          //     name: '全部'
          //   }]
          // }
          if (tabsCfg?.type === 'fk_col' && tabsCfg?.srvInfo && tabsCfg?.srvInfo.key_disp_col && tabsCfg
            ?.srvInfo
            .refed_col) {
            let tabs = await this.getFkTabs(tabsCfg?.srvInfo)
            if (Array.isArray(tabs) && tabs.length > 0) {
              tabs = tabs.map(item => {
                return {
                  name: item[tabsCfg?.srvInfo.key_disp_col],
                  value: item[tabsCfg?.srvInfo.refed_col]
                }
                return item
              })
            }

            tabsCfg.tabs = [...tabsCfg.tabs, ...tabs];
          } else if (tabsCfg?.type === 'enum_col' && tabsCfg?.column) {

            if (Array.isArray(colVs?._fieldInfo)) {
              let col = colVs?._fieldInfo.find(item => item.column === tabsCfg.column)
              let allTab = []
              if (col?.col_type === 'Enum' && col?.option_list_v2 && col?.option_list_v2?.length) {
                allTab = col.option_list_v2
              }
              if (Array.isArray(tabsCfg.customTabs) && tabsCfg.customTabs.length > 0) {
                allTab = tabsCfg.customTabs
              }
              if (Array.isArray(allTab) && allTab.length > 0) {
                allTab.forEach(item => {
                  tabsCfg.tabs.push({
                    name: item.label,
                    value: item.value
                  })
                })
              }
            }
          }
          
          if (tabsCfg?.default && Array.isArray(tabsCfg.tabs)) {
            const index = tabsCfg.tabs.findIndex(item => item.value === tabsCfg.default)
            if (index !== -1) {
              this.curTab = index;
              this.curTabVal = tabsCfg.tabs[index].value
            }
          }
          
          if (tabsCfg?.show_badge == true) {
            // 每个tab项右上方显示badge
            let tabs = await this.getTabsCount(tabsCfg.tabs, tabsCfg?.column)
            tabsCfg.tabs = tabs
          }
          
          if (tabsCfg?.show_total_tab !== false) {
            let totalTab = {
              value: '_all',
              name: '全部'
            }
            if (tabsCfg?.show_total_badge !== false) {
              totalTab.count = tabsCfg.tabs.reduce((res, cur) => res += cur.count || 0, 0)
            }
            tabsCfg.tabs.unshift(totalTab)
          }
          
          this.tabsCfg = tabsCfg
        }
        this.colV2 = colVs;
        if (Array.isArray(colVs.srv_cols)) {
          this.orderCols = colVs.srv_cols.filter(item => {
            if (item.in_list === 1) {
              item.orderType = 'asc';
              item.selected = false;
              return true;
            }
          });
        }
        return colVs;
      },
      // 查找每个tabs数据条数
      async getTabsCount(tabs, column) {
        if (Array.isArray(tabs) && tabs.length > 0 && column) {
          let req = tabs.map(item => {
            let obj = {
              "serviceName": this.serviceName,
              "colNames": ["*"],
              "condition": [
                ...this.condition, {
                  "colName": column,
                  "ruleType": "in",
                  "value": item.value
                }
              ],
              "page": {
                "rownumber": 1,
                "pageNo": 1
              }
            }
            return obj
          })
      
          const app = this.appName || uni.getStorageSync('activeApp')
          let res = await this.$fetch('multi', 'select', req, app);
          if (Array.isArray(res?.data) && res.data.length === tabs.length) {
            tabs = tabs.map((item, index) => {
              let page = res?.data[index]?.page
              item.count = page?.total || 0
              return item
            })
          }
        }
        return tabs
      },
      
      
      async getList(cond, initCond) {
        if (!cond) {
          if (!this.curTabVal && Array.isArray(this.enumTabs) && this.enumTabs.length > 0) {
            this.curTabVal = this.enumTabs[0].value
          }
          if (this.curTabVal && this.tabsCfg?.col && Array.isArray(this.tabsCfg.tabs)) {
            let index = this.tabsCfg.tabs.findIndex(item => item.value === this.curTabVal);
            if (index >= 0) {
              this.changeTab(index)
              return
            }
          }
        }
        let serviceName = this.serviceName;
        let app = this.appName || uni.getStorageSync('activeApp');
        let url = this.getServiceUrl(app, serviceName, 'select');
        let req = {
          serviceName: serviceName,
          colNames: ['*'],
          condition: this.condition || [],
          page: {
            rownumber: this.rownumber,
            pageNo: this.pageNo
          },
          order: this.orderList
        };
        if (this.listType === 'proc') {
          if (proc_data_type || this.proc_data_type) {
            req['proc_data_type'] = proc_data_type || this.proc_data_type;
          } else {
            req['proc_data_type'] = 'wait';
          }
        }
        if (Array.isArray(cond) && cond.length > 0) {
          req.condition = req.condition.concat(cond);
        }
        if (Array.isArray(this.config?.condition) && this.config.condition.length > 0 && this.tabs.length <
          1) {
          let data = {
            userInfo: this.$store?.state?.user?.userInfo,
            storeInfo: this.$store?.state?.app?.storeInfo,
            bindUserInfo: this.$store?.state?.user?.storeUserInfo
          };
          this.config.condition.forEach(cond => {
            let obj = {};
            obj.colName = cond.colName;
            obj.ruleType = cond.ruleType;
            obj.value = this.renderStr(cond.value, data);
            req.condition.push(obj);
          });
        }
        if (Array.isArray(this.config?.relation_condition?.data) && this.config.relation_condition?.data
          .length > 0 &&
          this
          .tabs.length < 1) {
          let data = {
            userInfo: this.$store?.state?.user?.userInfo,
            storeInfo: this.$store?.state?.app?.storeInfo,
            bindUserInfo: this.$store?.state?.user?.storeUserInfo
          };
          try {
            req.relation_condition = JSON.parse(this.renderStr(JSON.stringify(this.config
              ?.relation_condition), data));
          } catch (err) {
            console.log(err);
          }
        }
        if ((Array.isArray(this.config?.group) && this.config.group.length > 0)) {
          req.group = this.config.group
        }
        if (Array.isArray(this.tabs) && this.tabs.length > 0) {
          let cur = this.tabs[this.curTab]
          if (cur && cur.condition) {

            let data = {
              userInfo: this.$store?.state?.user?.userInfo,
              storeInfo: this.$store?.state?.app?.storeInfo,
              bindUserInfo: this.$store?.state?.user?.storeUserInfo
            };
            cur.condition = cur.condition.map(item => {
              item.value = this.renderStr(item.value, data)
              return item
            })

          }
          if (Array.isArray(cur.condition) && cur.condition.length > 0) {
            req.condition = [...req.condition, ...cur.condition]
          }
        }
        if (Array.isArray(initCond) && initCond.length > 0) {
          req.condition = [...req.condition, ...initCond];
        }

        let keywords = this.searchVal;
        if (keywords && this.finalSearchColumn) {
          if (typeof this.finalSearchColumn === 'string') {
            req.condition = req.condition.concat([{
              colName: this.finalSearchColumn,
              ruleType: 'like',
              value: keywords
            }]);
          } else if (Array.isArray(this.finalSearchColumn)) {
            // 数组 使用relation_condition
            if (Array.isArray(req.condition) && req.condition.length > 0) {
              req.relation_condition = {
                relation: "AND",
                data: [{
                    relation: "OR",
                    data: this.finalSearchColumn.map(item => {
                      return {
                        "colName": item,
                        "value": keywords,
                        "ruleType": 'like'
                      }
                    })
                  },
                  {
                    relation: "AND",
                    data: this.deepClone(req.condition)
                  }
                ]
              }
            } else {
              req.relation_condition = {
                relation: "OR",
                data: this.finalSearchColumn.map(itme => {
                  return {
                    "colName": itme,
                    "value": keywords,
                    "ruleType": 'like'
                  }
                })
              }
            }
            // delete req.condition
          }
        }
        if (Array.isArray(this.relationCondition?.data) && this.relationCondition.data.length > 0) {
          if (req.relation_condition?.data.length > 0) {
            req.relation_condition = {
              relation: 'AND',
              data: [
                ...this.relationCondition.data,
                {
                  relation: 'OR',
                  data: req.relation_condition
                }
              ]
            };
          } else {
            req.relation_condition = this.relationCondition;
          }
        }

        if (this.colV2?.vpage_no) {
          req['vpage_no'] = this.colV2.vpage_no;
        }
        this.loadStatus = 'loading';

        let res = await this.$http.post(url, req);

        if (res.data.state === 'SUCCESS') {
          if (this.pageNo === 1) {
            this.list = [];
          }
          this.list = this.list.concat(res.data.data);
          this.pageNo = res.data.page.pageNo;
          this.total = res.data.page.total;
          uni.$emit('setTotal', this.total)
          let page = res.data.page;
          if (this.listType === 'proc') {
            for (let i = 0; i < this.tabList.length; i++) {
              let item = this.tabList[i];
              if (item.proc_data_type === req.proc_data_type) {
                item.data = this.list;
                item.total = res.data.page.total;
                item.page = res.data.page;
                this.$set(this.tabList, i, item);
              }
            }
            this.list = [];
            this.list = this.tabList[this.TabCur]['data'];
            let callBackData = {
              data: this.list,
              page: res.data.page,
              proc_data_type: req.proc_data_type
            };
            return callBackData;
          } else {
            if (page.rownumber * page.pageNo >= page.total) {
              this.loadStatus = 'noMore';
            } else {
              this.loadStatus = 'more';
            }
          }
          return this.list;
        }
      },
      async clickFootBtn(data) {
        await this.checkUserInfo()
        // if (this.hasNotRegInfo) {
        //   uni.navigateTo({
        //     url: '/publicPages/accountExec/accountExec'
        //   })
        //   return
        // }
        let self = this;
        let buttonInfo = this.deepClone(data.button);
        let rowData = this.deepClone(data.row);
        if (buttonInfo?.more_config) {
          try {
            buttonInfo.moreConfig = JSON.parse(buttonInfo.more_config);
          } catch (err) {
            console.log(err);
          }
        }
        if (buttonInfo?._buttons) {
          delete buttonInfo._buttons;
        }
        if (!buttonInfo?.button_type) {
          uni.showModal({
            title: '提示',
            content: '按钮操作参数配置有误',
            showCancel: false
          });
          return;
        }
        if (buttonInfo.operate_params && typeof buttonInfo.operate_params === 'string') {
          // 序列化操作参数
          try {
            buttonInfo.operate_params = JSON.parse(buttonInfo.operate_params);
            if (Array.isArray(buttonInfo.operate_params?.condition) && buttonInfo.operate_params.condition
              .length > 0) {
              buttonInfo.operate_params.condition.forEach(cond => {
                if (typeof cond.value === 'object' && cond.value.value_type === 'rowData') {
                  cond.value = rowData[cond.value.value_key];
                } else if (typeof cond.value === 'object' && cond.value.value_type ===
                  'constant') {
                  cond.value = cond.value.value;
                } else if (typeof cond.value === 'object' && cond.value.value_type ===
                  'globalVariable') {
                  // 全局变量
                  const globalVariable = {
                    storeUser: this.vstoreUser,
                    loginUser: this.vloginUser,
                    userInfo: this.userInfo,
                    storeInfo: this.storeInfo
                  }
                  cond.value = this.renderStr(cond.value.value_key, globalVariable)
                }
              });
            }

            if (Array.isArray(buttonInfo.operate_params?.data) && buttonInfo.operate_params.data.length >
              0) {
              buttonInfo.operate_params.data.forEach(data => {
                if (typeof data === 'object') {
                  Object.keys(data).forEach(item => {
                    if (typeof data[item] === 'object' && data[item].value_type ===
                      'rowData') {
                      data[item] = rowData[data[item].value_key];
                    } else if (typeof data[item] === 'object' && data[item]
                      .value_type === 'constant') {
                      data[item] = data[item].value;
                    } else if (typeof data[item] === 'object' && data[item]
                      .value_type === 'globalVariable') {
                      // 全局变量
                      const globalVariable = {
                        storeUser: this.vstoreUser,
                        loginUser: this.vloginUser,
                        userInfo: this.userInfo,
                        storeInfo: this.storeInfo
                      }
                      data[item] = this.renderStr(data[item].value_key,
                        globalVariable)
                    } else {}
                  });
                }
              });
            }
          } catch (e) {
            //TODO handle the exception
          }
        }

        if (buttonInfo.button_type === 'customize') {
          if (buttonInfo.operate_type === '删除') {
            this.onButtonToUrl(data, this.appName).then(res => {
              if (res.state === 'SUCCESS') {
                this.refresh();
              }
            });
          } else if (buttonInfo.operate_type === '操作' && buttonInfo.operate_mode === '静默操作') {
            let req = [{
              serviceName: buttonInfo.operate_service,
              condition: buttonInfo.operate_params.condition,
              data: buttonInfo.operate_params.data
            }];
            if (!buttonInfo.operate_params.data && buttonInfo.servcie_type === 'update') {
              uni.showModal({
                title: '提示',
                content: '按钮操作参数配置有误',
                showCancel: false
              });
              return;
            }
            let app = this.appName || uni.getStorageSync('activeApp');
            let url = this.getServiceUrl(buttonInfo.application || app, buttonInfo.operate_service,
              buttonInfo.servcie_type);

            uni.showModal({
              title: '提示',
              content: '是否确认操作?',
              success: res => {
                if (res.confirm) {
                  this.$http.post(url, req).then(res => {
                    if (res.data.state === 'SUCCESS') {
                      this.refresh();
                    }
                  });
                }
              }
            });
            // let res = await this.$http.post(url, req);
            // if (res.data.state === 'SUCCESS') {
            //   // this.getList()
            //   this.refresh()
            // }
            return;
          } else if (buttonInfo.operate_type === 'URL跳转') {
            let storeInfo = this.$store?.state?.app?.storeInfo;
            let bindUserInfo = this.$store?.state?.user?.storeUserInfo;

            let obj = {
              data: rowData,
              rowData,
              storeInfo,
              bindUserInfo,
              storeUser: bindUserInfo
            };
            if (buttonInfo?.moreConfig?.navUrl) {
              let url = this.renderStr(buttonInfo.moreConfig.navUrl, obj);
              uni.navigateTo({
                url
              });
            }
          } else if (buttonInfo.operate_type === '详情弹出' || buttonInfo.operate_type === '详情跳转') {
            let storeInfo = this.$store?.state?.app?.storeInfo;
            let bindUserInfo = this.$store?.state?.user?.storeUserInfo;

            // let targetUrl = this.customDetailUrl
            // let obj = {
            //   data: rowData,
            //   rowData,
            //   storeInfo,
            //   bindUserInfo
            // };
            // obj = this.deepClone(obj)
            // targetUrl = this.renderStr(this.customDetailUrl, obj)
            let url = `/publicPages/detail/detail?serviceName=${buttonInfo.service_name}`;
            // }

            let condition = buttonInfo?.operate_params?.condition;
            if (Array.isArray(condition) && condition.length > 0) {
              url += `&cond=${JSON.stringify(condition)}`;
            } else {
              return;
            }
            if (this.appName) {
              url += `&appName=${this.appName}`;
            }
            uni.navigateTo({
              url: url
            });
            return;
          } else if (buttonInfo.operate_type === '更新弹出' || buttonInfo.operate_type === '更新跳转') {
            // 自定义按钮
            let moreConfig = buttonInfo.more_config;
            if (moreConfig && typeof moreConfig === 'string') {
              try {
                moreConfig = JSON.parse(moreConfig);
              } catch (e) {
                //TODO handle the exception
                console.log(e);
              }
            }
            if (buttonInfo.servcie_type === 'add') {
              let params = {
                type: 'add',
                serviceName: buttonInfo.service_name,
                defaultVal: rowData,
                eventOrigin: buttonInfo
              };
              uni.navigateTo({
                url: '/pages/public/formPage/formPage?params=' + JSON.stringify(params)
              });
              return;
            } else if (buttonInfo.servcie_type === 'select') {
              let params = {
                type: 'select',
                serviceName: buttonInfo.service_name,
                defaultVal: rowData,
                eventOrigin: buttonInfo
              };
              if (buttonInfo.operate_params && Array.isArray(buttonInfo.operate_params.condition)) {
                let viewTemp = {};
                if (buttonInfo.service_name === 'srvhealth_store_vaccination_appoint_record_select') {
                  viewTemp = {
                    title: 'customer_name',
                    img: 'person_image'
                  };
                }
                uni.navigateTo({
                  url: '/publicPages/list/list?pageType=list&serviceName=' +
                    buttonInfo.service_name +
                    '&cond=' +
                    JSON.stringify(buttonInfo.operate_params.condition) +
                    '&viewTemp=' +
                    JSON.stringify(viewTemp)
                });
                return;
              }
            } else if (buttonInfo.servcie_type === 'update' || buttonInfo.servcie_type === 'operate') {
              let params = {
                type: 'update',
                serviceName: buttonInfo.service_name,
                defaultVal: rowData,
                eventOrigin: buttonInfo
              };
              let fieldsCond = [];
              let condition = buttonInfo?.operate_params?.condition;
              let defaultVal = buttonInfo?.operate_params?.data;
              if (Array.isArray(defaultVal) && defaultVal.length > 0) {
                let obj = defaultVal[0];
                if (this.iObject(obj)) {
                  Object.keys(obj).forEach(key => {
                    fieldsCond.push({
                      column: key,
                      value: obj[key]
                    });
                  });
                }
              }
              // if (Array.isArray(condition) && condition.length > 0) {
              //   condition.forEach(cond => {
              //     fieldsCond.push({
              //       column: cond.colName,
              //       value: cond.value
              //     })
              //   })
              // }
              if (fieldsCond.length === 0) {
                fieldsCond = [{
                  column: 'id',
                  value: rowData.id
                }];
              }
              let url =
                `/publicPages/formPage/formPage?service=${buttonInfo.service}&serviceName=${buttonInfo.service_name}&type=${buttonInfo.servcie_type}&fieldsCond=` +
                encodeURIComponent(JSON.stringify(fieldsCond));
              if (this.appName) {
                url += `&appName=${this.appName}`;
              }
              if (Array.isArray(condition) && condition.length > 0) {
                url += `&condition=${JSON.stringify(condition)}`;
              }
              uni.navigateTo({
                url: url
              });
              return;
            }
            return;
          } else if (buttonInfo.operate_type === '列表跳转') {
            // debugger
            // let serviceName = buttonInfo.service_name;
            // let
            let app = buttonInfo.application;
            let url = '/publicPages/list2/list2?pageType=list&serviceName=' + buttonInfo.service_name +
              '&cond=' + JSON.stringify(buttonInfo.operate_params.condition);

            if (app) {
              url += `&destApp=${app}`;
            }
            uni.navigateTo({
              url
            });
            return;
          } else if (buttonInfo.operate_type === '增加跳转' || buttonInfo.operate_type === '增加弹出') {
            let fieldsCond = [];
            if (Array.isArray(buttonInfo.operate_params?.condition) && buttonInfo.operate_params.condition
              .length > 0) {
              buttonInfo.operate_params.condition.forEach(item => {
                let obj = {
                  column: item.colName,
                  value: item.value,
                  disabled: true
                };
                fieldsCond.push(obj);
              });
            }
            if (Array.isArray(buttonInfo.operate_params?.data) && buttonInfo.operate_params.data.length >
              0) {
              buttonInfo.operate_params.data.forEach(item => {
                Object.keys(item).forEach(key => {
                  let obj = {
                    column: key,
                    value: item[key],
                    disabled: true
                  };
                  fieldsCond.push(obj);
                });
              });
            }
            let url = `/publicPages/formPage/formPage?type=add&serviceName=${buttonInfo.service_name}&fieldsCond=${JSON.stringify(fieldsCond)}&destApp=${
						buttonInfo.application
					}`;
            uni.navigateTo({
              url
            });
            return;
          }
        } else if (this.listType === 'proc') {
          if (buttonInfo && buttonInfo.button_type === 'edit' && rowData.proc_instance_no) {
            uni.navigateTo({
              url: '/publicPages/procDetail/procDetail?proc_instance_no=' + rowData
                .proc_instance_no
            });
          }
        } else {
          let customDetailUrl = this.customDetailUrl

          if (this.config?.customDetailUrl) {
            customDetailUrl = this.config?.customDetailUrl
          }

          if (this.tabs.length > 0 && this.tabs[this.curTab].customDetailUrl) {
            customDetailUrl = this.tabs[this.curTab].customDetailUrl
          }

          if (buttonInfo.button_type === 'detail' && customDetailUrl) {
            let storeInfo = this.$store?.state?.app?.storeInfo;
            let bindUserInfo = this.$store?.state?.user?.storeUserInfo;
            let targetUrl = customDetailUrl;
            let obj = {
              data: rowData,
              rowData,
              storeInfo,
              bindUserInfo
            };
            obj = this.deepClone(obj);
            targetUrl = this.renderStr(customDetailUrl, obj);
            if (targetUrl && targetUrl.indexOf('"value":""') !== -1) {
              let condition = buttonInfo?.operate_params?.condition;
              let fieldsCond = [{
                column: 'id',
                value: rowData.id
              }];
              let url =
                `/publicPages/formPage/formPage?serviceName=${buttonInfo.service_name}&type=detail&fieldsCond=` +
                encodeURIComponent(JSON.stringify(fieldsCond));

              // if (this.list_config?.detailPage === 'childTableList' || this.moreConfig?.detailPage ===
              //   'childTableList') {
              url =
                `/publicPages/detail/detail?serviceName=${buttonInfo.service_name}&fieldsCond=${JSON.stringify(fieldsCond)}`;
              // }
              if (this.hideChildList) {
                url =
                  `/publicPages/formPage/formPage?type=detail&serviceName=${buttonInfo.service_name}&fieldsCond=${JSON.stringify(fieldsCond)}`;
              }
              if (Array.isArray(condition) && condition.length > 0) {
                url += `&condition=${JSON.stringify(condition)}`;
              }
              if (this.appName) {
                url += `&appName=${this.appName}`;
              }
              targetUrl = url;
            }
            if (targetUrl && targetUrl.indexOf(('/pages/home/home') == 0)) {
              targetUrl = targetUrl.replace('/pages/home/home', '/storePages/home/home')
            }
            uni.navigateTo({
              url: targetUrl
            });
            return;
          }

          this.onButtonToUrl(data, this.appName).then(res => {
            if (buttonInfo && buttonInfo.button_type === 'delete') {
              if (res.state === 'SUCCESS') {
                // this.getList()
                this.refresh();
              }
            }
            if (buttonInfo && buttonInfo.button_type === 'detail') {
              let {
                row,
                button
              } = res;
              let fieldsCond = [];
              if (row && row.id) {
                fieldsCond = [{
                  column: 'id',
                  value: row.id,
                  display: false
                }];
              } else {
                if (typeof row == 'object' && Object.keys(row).length > 0) {
                  Object.keys(row).forEach(key => {
                    if (key !== '_buttons' && row[key]) {
                      let obj = {
                        column: key,
                        value: row[key] || ''
                      };
                      fieldsCond.push(obj);
                    }
                  });
                }
              }
              let url =
                `/publicPages/formPage/formPage?type=detail&serviceName=${button.service_name}&fieldsCond=${JSON.stringify(fieldsCond)}`;
              // if (this.list_config?.detailPage === 'childTableList' || this.moreConfig?.detailPage ===
              //   'childTableList') {
              url =
                `/publicPages/detail/detail?serviceName=${button.service_name}&fieldsCond=${JSON.stringify(fieldsCond)}`;
              // }
              if (this.hideChildList) {
                url =
                  `/publicPages/formPage/formPage?type=detail&serviceName=${button.service_name}&fieldsCond=${JSON.stringify(fieldsCond)}`;
              }
              if (this.appName) {
                url += `&appName=${this.appName}`;
              }
              // if (button.service_name === 'srvdaq_cms_content_select') {
              //   if (rowData.content_no) {
              //     uni.navigateTo({
              //       url: `/publicPages/article/article?serviceName=srvdaq_cms_content_select&content_no=${rowData.content_no}`
              //     });
              //   }
              //   return
              // }
              uni.navigateTo({
                url: url
              });
            } else if (buttonInfo && buttonInfo.button_type === 'customize') {
              // 自定义按钮
              let moreConfig = buttonInfo.more_config;
              if (moreConfig && typeof moreConfig === 'string') {
                try {
                  moreConfig = JSON.parse(moreConfig);
                } catch (e) {
                  //TODO handle the exception
                  console.log(e);
                }
              }
              if (buttonInfo.servcie_type === 'add') {
                let params = {
                  type: 'add',
                  serviceName: buttonInfo.service_name,
                  defaultVal: rowData,
                  eventOrigin: buttonInfo
                };
                uni.navigateTo({
                  url: '/pages/public/formPage/formPage?params=' + JSON.stringify(
                    params)
                });
              } else if (buttonInfo.servcie_type === 'select') {
                let params = {
                  type: 'select',
                  serviceName: buttonInfo.service_name,
                  defaultVal: rowData,
                  eventOrigin: buttonInfo
                };
                if (buttonInfo.operate_params && Array.isArray(buttonInfo.operate_params
                    .condition)) {
                  let viewTemp = {};
                  if (buttonInfo.service_name ===
                    'srvhealth_store_vaccination_appoint_record_select') {
                    viewTemp = {
                      title: 'customer_name',
                      img: 'person_image'
                    };
                  }
                  uni.navigateTo({
                    url: '/publicPages/list/list?pageType=list&serviceName=' +
                      buttonInfo.service_name +
                      '&cond=' +
                      JSON.stringify(buttonInfo.operate_params.condition) +
                      '&viewTemp=' +
                      JSON.stringify(viewTemp)
                  });
                }
              } else if (buttonInfo.servcie_type === 'update') {
                let params = {
                  type: 'update',
                  serviceName: buttonInfo.service_name,
                  defaultVal: rowData,
                  eventOrigin: buttonInfo
                };
                let fieldsCond = [];
                if (Array.isArray(this.condition)) {
                  fieldsCond = this.condition.map(item => {
                    return {
                      column: item.colName,
                      value: item.value,
                      display: false
                    };
                  });
                }
                let condition = buttonInfo?.operate_params?.condition;
                let defaultVal = buttonInfo?.operate_params?.data;
                if (Array.isArray(defaultVal) && defaultVal.length > 0) {
                  let obj = defaultVal[0];
                  if (this.iObject(obj)) {
                    Object.keys(obj).forEach(key => {
                      fieldsCond.push({
                        column: key,
                        value: obj[key]
                      });
                    });
                  }
                }
                if (Array.isArray(condition) && condition.length > 0) {
                  condition.forEach(cond => {
                    fieldsCond.push({
                      column: cond.colName,
                      value: cond.value
                    });
                  });
                }
                let url =
                  `/publicPages/formPage/formPage?service=${buttonInfo.service}&serviceName=${buttonInfo.service_name}&type=${buttonInfo.servcie_type}&fieldsCond=` +
                  encodeURIComponent(JSON.stringify(fieldsCond));
                if (this.appName) {
                  url += `&appName=${this.appName}`;
                }
                uni.navigateTo({
                  url: url
                });
              }
            } else if (buttonInfo && buttonInfo.button_type === 'duplicate') {
              let fieldsCond = [];
              if (Array.isArray(self.condition)) {
                self.condition.forEach(item => {
                  fieldsCond.push({
                    column: item.colName,
                    value: item.value,
                    display: false
                  });
                });
              }
              Object.keys(rowData).forEach(key => {
                if (
                  !['id', 'modify_user_disp', 'modify_user', 'modify_time',
                    'create_user_disp', 'create_user', 'create_time', 'del_flag',
                    '_buttons'
                  ].includes(key) &&
                  rowData[key]
                ) {
                  if (!fieldsCond.find(item => item.column === key)) {
                    fieldsCond.push({
                      column: key,
                      display: true,
                      value: rowData[key]
                    });
                  }
                }
              });

              let url =
                `/publicPages/formPage/formPage?serviceName=${buttonInfo.service_name}&type=add&fieldsCond=${JSON.stringify(fieldsCond)}`;
              if (self.appName) {
                url += `&appName=${self.appName}`;
              }
              uni.navigateTo({
                url: url
              });
            } else if (buttonInfo.servcie_type === 'add') {
              let params = {
                type: 'add',
                serviceName: res.button.service_name,
                defaultVal: res.row,
                eventOrigin: res.button
              };
              uni.navigateTo({
                url: '/pages/public/formPage/formPage?params=' + JSON.stringify(params)
              });
            } else if (buttonInfo && buttonInfo.operate_type === '流程申请') {
              uni.navigateTo({
                url: '/pages/public/proc/apply/apply?serviceName=' + buttonInfo
                  .operate_service
              });
            }
          });
        }
        console.log('clickFootBtn:', data);
      }
    },
    mounted() {
      if (this.serviceName) {
        this.loading = true
        this.getListV2().then(_ => {
          this.refresh().then(_ => {
            this.loading = false
          })
        });
      }
    },
    onReachBottom() {
      if (this.loadStatus === 'more') {
        this.pageNo++;
        this.getList(null, this.initCond);
      }
    },
    onPullDownRefresh() {
      this.refresh();
      setTimeout(_ => {
        uni.stopPullDownRefresh();
      }, 500);
    }
  };
</script>

<style lang="scss" scoped>
  .list-box {
    // min-height: calc(100vh - var(--window-top));
    display: flex;
    flex-direction: column;
    overflow: hidden;
    padding: 0 10px;

    .data-empty {
      min-height: 300px;
      display: flex;
      align-items: center;
      justify-content: center;
    }

    .title {
      font-size: 16px;
      padding: 10rpx;
      display: flex;
      justify-content: space-between;
    }

    .list-content {
      flex: 1;
      display: flex;
      flex-direction: column;
      overflow: hidden;
      margin-top: 5px;

      .list-view {
        flex: 1;
        overflow-y: scroll;
      }
    }
  }
</style>
